import java.awt.*;
import java.util.Random;

/* Radio class for the VOR.
 * Sends a signal back to the main
 * class if the signal is good or bad
 * based on the calculations and also 
 * returns a random morse code back to
 * the main
 *
 * Andy Tonthat, Jaimar John Sison, Chris Caoagdan.
 */


public class Radio {

	Calculations calc = new Calculations();

	/**
	 * @param args
	 */

	public Radio(){
		
		calc = new Calculations();
		
	}
	
	/* Class to generate a random integer
	 * between 0 and 359. Needed
	 * for the random radial of the
	 * radio.
	 */
	 int generateRandomInteger(int aStart, int aEnd, Random aRandom){
		    if (aStart > aEnd) {
		      throw new IllegalArgumentException("Start cannot exceed End.");
		    }
		    //get the range, casting to long to avoid overflow problems
		    long range = (long)aEnd - (long)aStart + 1;
		    // compute a fraction of the range, 0 <= frac < range
		    long fraction = (long)(range * aRandom.nextDouble());
		    int randomNumber =  (int)(fraction + aStart);
			return randomNumber; 
		  }
	
	 public int OBS(){
		 boolean abeam;
		 abeam = calc.getAbeam();
		 Random random = new Random();
		 int ranNum = generateRandomInteger(0, 4, random);
		 
		 //if value is greater than 90, return BAD
		 if(abeam == true){
			 
			 return 0;
			 
		 }
		 //there is a 1 in 5 chance that the plane will be on top of the VOR station
		 //and thus still return BAD.
		 else if(ranNum == 0){
			 return 0;
		 }
		 //else return GOOD
		 else{
			 return 1;
		 }
		 
	 }
    
     
	 /* returns random three letter morse code.
	  * 
	  */
	 public String morseCode(){
		 
		    String[] dottie = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
		            "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
		            "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-",
		            "-.--", "--..", };
		    
		    String morse = "";
		    for(int i = 0; i < 3; i++){
		    	Random random = new Random();
				int ranNum = generateRandomInteger(0, 25, random);
		    	morse += dottie[ranNum] + " ";
		    	
		    }
		    
		    return morse;
		 
	 }
}


